package com.ruoyi.report_lqn.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_lqn.domain.bo.ReportLqnRhlqdhjlbBsInfoBo;
import com.ruoyi.report_lqn.domain.vo.ReportLqnRhlqdhjlbBsInfoVo;
import com.ruoyi.report_lqn.domain.ReportLqnRhlqdhjlbBsInfo;
import com.ruoyi.report_lqn.mapper.ReportLqnRhlqdhjlbBsInfoMapper;
import com.ruoyi.report_lqn.service.IReportLqnRhlqdhjlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 乳化沥青筛上剩余量、微粒离子电荷试验检测记录Service业务层处理
 *
 * @author tll
 * @date 2024-09-12
 */
@RequiredArgsConstructor
@Service
public class ReportLqnRhlqdhjlbBsInfoServiceImpl implements IReportLqnRhlqdhjlbBsInfoService {

    private final ReportLqnRhlqdhjlbBsInfoMapper baseMapper;

    /**
     * 查询乳化沥青筛上剩余量、微粒离子电荷试验检测记录
     */
    @Override
    @FIllBasicInfo
    public ReportLqnRhlqdhjlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询乳化沥青筛上剩余量、微粒离子电荷试验检测记录列表
     */
    @Override
    public TableDataInfo<ReportLqnRhlqdhjlbBsInfoVo> queryPageList(ReportLqnRhlqdhjlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportLqnRhlqdhjlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportLqnRhlqdhjlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询乳化沥青筛上剩余量、微粒离子电荷试验检测记录列表
     */
    @Override
    public List<ReportLqnRhlqdhjlbBsInfoVo> queryList(ReportLqnRhlqdhjlbBsInfoBo bo) {
        LambdaQueryWrapper<ReportLqnRhlqdhjlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportLqnRhlqdhjlbBsInfo> buildQueryWrapper(ReportLqnRhlqdhjlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportLqnRhlqdhjlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, ReportLqnRhlqdhjlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, ReportLqnRhlqdhjlbBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportLqnRhlqdhjlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportLqnRhlqdhjlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportLqnRhlqdhjlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportLqnRhlqdhjlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportLqnRhlqdhjlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportLqnRhlqdhjlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportLqnRhlqdhjlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(bo.getYangpsj() != null, ReportLqnRhlqdhjlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportLqnRhlqdhjlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportLqnRhlqdhjlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportLqnRhlqdhjlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportLqnRhlqdhjlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportLqnRhlqdhjlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportLqnRhlqdhjlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportLqnRhlqdhjlbBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobmc()), ReportLqnRhlqdhjlbBsInfo::getBaobmc, bo.getBaobmc());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobbh()), ReportLqnRhlqdhjlbBsInfo::getBaobbh, bo.getBaobbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportLqnRhlqdhjlbBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancr()), ReportLqnRhlqdhjlbBsInfo::getJiancr, bo.getJiancr());
        lqw.eq(StringUtils.isNotBlank(bo.getJilr()), ReportLqnRhlqdhjlbBsInfo::getJilr, bo.getJilr());
        lqw.eq(StringUtils.isNotBlank(bo.getFuhr()), ReportLqnRhlqdhjlbBsInfo::getFuhr, bo.getFuhr());
        lqw.eq(bo.getRiq() != null, ReportLqnRhlqdhjlbBsInfo::getRiq, bo.getRiq());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportLqnRhlqdhjlbBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportLqnRhlqdhjlbBsInfo::getJiancyjIds, bo.getJiancyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportLqnRhlqdhjlbBsInfo::getPandyjIds, bo.getPandyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getQuydd()), ReportLqnRhlqdhjlbBsInfo::getQuydd, bo.getQuydd());
        lqw.eq(StringUtils.isNotBlank(bo.getRuhlqpz()), ReportLqnRhlqdhjlbBsInfo::getRuhlqpz, bo.getRuhlqpz());
        lqw.eq(StringUtils.isNotBlank(bo.getRuhlqdh()), ReportLqnRhlqdhjlbBsInfo::getRuhlqdh, bo.getRuhlqdh());
        lqw.eq(StringUtils.isNotBlank(bo.getRuhlqcd()), ReportLqnRhlqdhjlbBsInfo::getRuhlqcd, bo.getRuhlqcd());
        lqw.eq(StringUtils.isNotBlank(bo.getRuhlqzl()), ReportLqnRhlqdhjlbBsInfo::getRuhlqzl, bo.getRuhlqzl());
        lqw.eq(StringUtils.isNotBlank(bo.getRuhlqbh()), ReportLqnRhlqdhjlbBsInfo::getRuhlqbh, bo.getRuhlqbh());
        lqw.eq(StringUtils.isNotBlank(bo.getShengylSybh1()), ReportLqnRhlqdhjlbBsInfo::getShengylSybh1, bo.getShengylSybh1());
        lqw.eq(bo.getShengylSym1() != null, ReportLqnRhlqdhjlbBsInfo::getShengylSym1, bo.getShengylSym1());
        lqw.eq(bo.getShengylSym11() != null, ReportLqnRhlqdhjlbBsInfo::getShengylSym11, bo.getShengylSym11());
        lqw.eq(bo.getShengylSym21() != null, ReportLqnRhlqdhjlbBsInfo::getShengylSym21, bo.getShengylSym21());
        lqw.eq(bo.getShengylSywm1() != null, ReportLqnRhlqdhjlbBsInfo::getShengylSywm1, bo.getShengylSywm1());
        lqw.eq(bo.getShengylPr1() != null, ReportLqnRhlqdhjlbBsInfo::getShengylPr1, bo.getShengylPr1());
        lqw.eq(StringUtils.isNotBlank(bo.getShengylSybh2()), ReportLqnRhlqdhjlbBsInfo::getShengylSybh2, bo.getShengylSybh2());
        lqw.eq(bo.getShengylSym2() != null, ReportLqnRhlqdhjlbBsInfo::getShengylSym2, bo.getShengylSym2());
        lqw.eq(bo.getShengylSym12() != null, ReportLqnRhlqdhjlbBsInfo::getShengylSym12, bo.getShengylSym12());
        lqw.eq(bo.getShengylSym22() != null, ReportLqnRhlqdhjlbBsInfo::getShengylSym22, bo.getShengylSym22());
        lqw.eq(bo.getShengylSywm2() != null, ReportLqnRhlqdhjlbBsInfo::getShengylSywm2, bo.getShengylSywm2());
        lqw.eq(bo.getShengylPr2() != null, ReportLqnRhlqdhjlbBsInfo::getShengylPr2, bo.getShengylPr2());
        lqw.eq(bo.getShengylPjz() != null, ReportLqnRhlqdhjlbBsInfo::getShengylPjz, bo.getShengylPjz());
        lqw.eq(StringUtils.isNotBlank(bo.getDianhSybh1()), ReportLqnRhlqdhjlbBsInfo::getDianhSybh1, bo.getDianhSybh1());
        lqw.eq(StringUtils.isNotBlank(bo.getDianhXfqk1()), ReportLqnRhlqdhjlbBsInfo::getDianhXfqk1, bo.getDianhXfqk1());
        lqw.eq(bo.getDianhCz1() != null, ReportLqnRhlqdhjlbBsInfo::getDianhCz1, bo.getDianhCz1());
        lqw.eq(StringUtils.isNotBlank(bo.getDianhLzlx()), ReportLqnRhlqdhjlbBsInfo::getDianhLzlx, bo.getDianhLzlx());
        return lqw;
    }

    /**
     * 新增乳化沥青筛上剩余量、微粒离子电荷试验检测记录
     */
    @Override
    public Boolean insertByBo(ReportLqnRhlqdhjlbBsInfoBo bo) {
        ReportLqnRhlqdhjlbBsInfo add = BeanUtil.toBean(bo, ReportLqnRhlqdhjlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改乳化沥青筛上剩余量、微粒离子电荷试验检测记录
     */
    @Override
    public Boolean updateByBo(ReportLqnRhlqdhjlbBsInfoBo bo) {
        ReportLqnRhlqdhjlbBsInfo update = BeanUtil.toBean(bo, ReportLqnRhlqdhjlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportLqnRhlqdhjlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除乳化沥青筛上剩余量、微粒离子电荷试验检测记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
